package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 2020-11-25 10:32
 *
 * https://leetcode-cn.com/problems/sub-sort-lcci/
 */
public class _面试题_16_16_部分排序 {

    public int[] subSort(int[] array) {

        int[]rank = new int[]{-1,-1};

        if (array == null || array.length <= 1) {

            return rank;
        }

        int right = -1;

        int max = array[0];
        for (int i = 1; i < array.length; i++) {

            // 这里要添加等号 如 1,2,4,5,5,5,5,6,8
            if (max <= array[i]) {

                max = array[i];
            }else {

                right = i;
            }
        }

        int left = -1;
        int min = array[array.length - 1];

        for (int i = array.length - 1; i >= 0; i--) {

            // 这里要添加等号 如 1,2,4,5,5,5,5,6,8
            if (min >= array[i]) {

                min = array[i];
            }else {

                left = i;
            }
        }

        return new int[]{left,right};
    }
}
